/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var removeZeroSumSublists = function (head) {
  let list = new ListNode(0)
  list.next = head
  let res = {}, pre = 0
  for (let node = list; node != null; node = node.next) {
    pre += node.val
    res[pre] = node
  }
  pre = 0
  for(let node=list;node!=null;node=node.next){
    pre+=node.val
    node.next=res[pre].next
  }
  return list.next
};